home *** CD-ROM | disk | FTP | other *** search
- #INCLUDE SlsApi.h
-
- *----------------Sheriff Class----------------------------
-
- DEFINE CLASS Sheriff AS CUSTOM
-
- PROTECTED m_hLicence,;
- m_lLastError,;
- m_cUserName,;
- m_cProductID,;
- m_cSecrets,;
- m_bSecretsSet;
-
- PROCEDURE Init
- PARAMETER cProductID, cUserName
-
- this.m_cProductID = cProductID
- this.m_cUserName = cUserName
-
- * Set to non-challenge mode by defautl
- * Challenge mode is set on by calling SetSecrets
- this.m_bSecretsSet = .F.
- ENDPROC
-
- PROCEDURE Destroy
- ENDPROC
-
- PROCEDURE SetSecrets
- PARAMETER cSecrets
-
- this.m_cSecrets=cSecrets
- this.m_bSecretsSet=.T.
- ENDPROC
-
- FUNCTION Succeeded()
- return this.m_lLastError = SLS_SUCCESS
- ENDFUNC
-
- FUNCTION GetLastError()
- return this.m_lLastError
- ENDFUNC
-
- PROCEDURE GetLastErrorMessage
- PARAMETER cErrorMessage
-
- cErrorMessage = REPLICATE(CHR(0),256)
- SLS_GetErrorMessage(this.m_lLastError ,cErrorMessage)
- ENDPROC
-
- FUNCTION QueryLicenceInfo
- PARAMETER cLicenceInfo
-
- this.m_lLastError = SLS_QueryLicenceInfo(this.m_cProductID, @cLicenceInfo)
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION GetReference
- PARAMETER cReference
-
- this.m_lLastError = SLS_GetReference(this.m_cProductID, @cReference)
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION SetLicence
- PARAMETER cReferenceCode,cLicenceKey
-
- this.m_lLastError = SLS_SetLicence(this.m_cProductID, cReferenceCode,cLicenceKey)
- return this.Succeeded()
- ENDFUNC
-
-
- *---------
- *Interface
- *---------
-
- FUNCTION Register
- PARAMETER cProductName,cLicencePath
-
- this.m_lLastError = SLS_Register(this.m_cProductID,cProductName,cLicensePath)
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION License
- PARAMETER cLicence
-
- if(!this.m_bSecretsSet)
- *Secrets Undefined
- this.m_lLastError=SLS_E_BAD_SECRET
- return .F.
- endif
-
- * Create Challenge
- cChallenge=REPLICATE(CHR(0),32) && size of SLS_Challenge
- this.m_lLastError=SLS_CreateChallenge(this.m_cSecrets,4,cLicence,28,&cChallenge)
- if(this.Succeeded())
- this.m_lLastError=SLS_License(this.m_cProductID,cLicence,&cChallenge)
- endif
-
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION Request
- PARAMETER cRequest,cPermit
-
- hLicence=0
- cChallenge=REPLICATE(CHR(0),32)
- if(this.m_bSecretsSet)
- *Create Challenge
- this.m_lLastError=SLS_CreateChallenge(this.m_cSecrets,4,cRequest,4,@cChallenge)
- if(this.Succeeded())
- this.m_lLastError=SLS_Request(this.m_cProductID,this.m_cUserName,@cRequest,@cPermit,@hLicence,@cChallenge)
- if(this.Succeeded())
- *Verify Challenge
- this.m_lLastError=SLS_VerifyChallenge(this.m_cSecrets,4,@cPermit,8,@cChallenge)
- endif
- endif
- else
- *No Challenge, set Challenge.Protocol to SLS_NO_PROTOCOL
- *cChallenge.Protocol=SLS_NO_PROTOCOL
- this.m_lLastError=SLS_Request(this.m_cProductID,this.m_cUserName,@cRequest,@cPermit,@hLicence,@cChallenge)
- endif
-
- this.m_hLicence=hLicence
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION Updates
- PARAMETER cUpdate,cPermit
-
- cChallenge=REPLICATE(CHR(0),32)
- if(this.m_bSecretsSet)
- *Create Challenge
- this.m_lLastError=SLS_CreateChallenge(this.m_cSecrets,4,cUpdate,8,@cChallenge)
- if(this.Succeeded())
- this.m_lLastError=SLS_Update(this.m_cProductID,this.m_hLicence,@cUpdate,@cPermit,@cChallenge)
- if(this.Succeeded())
- *Verify Challenge
- this.m_lLastError=SLS_VerifyChallenge(this.m_cSecrets,4,@cPermit,8,@cChallenge)
- endif
- endif
- else
- *No Challenge
- *cChallenge.Protocol=SLS_NO_PROTOCOL;
- this.m_lLastError=SLS_Update(this.m_cProductID,this.m_hLicence,@cUpdate,@cPermit,@cChallenge)
- endif
-
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION Releases
- PARAMETER cRelease
-
- cChallenge=REPLICATE(CHR(0),32)
- if(this.m_bSecretsSet)
- *Create Challenge
- m_lLastError=SLS_CreateChallenge(this.m_cSecrets,4,cRelease,4,@cChallenge)
- else
- *No Challenge
- *cChallenge.Protocol=SLS_NO_PROTOCOL;
-
- endif
-
- this.m_lLastError=SLS_Release(this.m_cProductID,this.m_hLicence,@cRelease,@cChallenge)
-
- return this.Succeeded()
- ENDFUNC
-
-
- *----------
- *Attributes
- *----------
-
- FUNCTION IsProductInstalled
-
- this.m_lLastError=SLS_IsProductInstalled(this.m_cProductID)
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION IsProductRegistered
-
- LOCAL cLicenceInfo
- cLicenceInfo=SPACE(52)
-
- this.m_lLastError=SLS_QueryLicenceInfo(this.m_cProductID,@cLicenceInfo)
- return this.Succeeded()
- ENDFUNC
-
- FUNCTION IsLicenceDefined
-
- LOCAL cLicenceInfo
- cLicenceInfo=SPACE(52)
-
- this.m_lLastError=SLS_QueryLicenceInfo(m_cProductID,@cLicenceInfo)
- if(!this.Succeeded())
- return .F.
- endif
-
- lState=FromLong(SUBSTR(cLicenceInfo,28,4))
- if(lState=SLS_STATE_UNDEFINED or lState=SLS_STATE_BAD)
- return .F.
- endif
-
- return .T.
- ENDFUNC
-
- FUNCTION IsLicenceValid
-
- LOCAL cLicenceInfo
- cLicenceInfo=SPACE(52)
-
- this.m_lLastError=SLS_QueryLicenceInfo(m_cProductID,@cLicenceInfo)
- if(!this.Succeeded())
- return .F.
- endif
-
- lState=FromLong(SUBSTR(cLicenceInfo,28,4))
-
- if(lState=SLS_STATE_OK)
- return .T.
- endif
-
- return .F.
- ENDFUNC
-
- FUNCTION SetOptions
- PARAMETER cOptions
-
- *-
- * Build the string for the SLS_MSG_DIGEST struct
- *-
- cMessageDigest = REPLICATE(CHR(0),16)
-
- *-
- * Build the string for the SLS_CHALLDATA struct
- *-
- nSecretIndex = 0
- nRandom = 0
- cChallengeData = ToLong(nSecretIndex) + ;
- ToLong(nRandom) + ;
- cMessageDigest
-
- *-
- * Build the string for the SLS_CHALLENGE struct
- *-
- nProtocol = SLS_NO_PROTOCOL
- if this.m_bSecretsSet
- nProtocol = SLS_BASIC_PROTOCOL
- endif
- nSize = 4
- cChallenge = ToLong(nProtocol) + ;
- ToLong(nSize) + ;
- cChallengeData
-
- *-
- * If secrets are being used,
- * create a challenge.
- *-
- if this.m_bSecretsSet
- this.m_lLastError = SLS_CreateChallenge(this.m_aSecrets, 4, ;
- cOption, 16, ;
- @cChallenge)
- if this.Succeeded()
- this.m_lLastError = SLS_SetOptions(this.m_cProductID, this.m_hLicence, ;
- cOptions, @cChallenge)
- endif
- else
- this.m_lLastError = SLS_SetOptions(this.m_cProductID, this.m_hLicence, ;
- cOptions, @cChallenge)
- endif
-
- return this.Succeeded()
- ENDFUNC
-
- ENDDEFINE
-